/** @file
 *	@brief MAVLink comm testsuite protocol generated from rams_msg.xml
 *	@see http://mavlink.org
 */

#pragma once

#include <gtest/gtest.h>
#include "rams_msg.hpp"

#ifdef TEST_INTEROP
using namespace mavlink;
#undef MAVLINK_HELPER
#include "mavlink.h"
#endif


TEST(rams_msg, ACC_DATA)
{
    mavlink::mavlink_message_t msg;
    mavlink::MsgMap map1(msg);
    mavlink::MsgMap map2(msg);

    mavlink::rams_msg::msg::ACC_DATA packet_in{};
    packet_in.time = 123.0;
    packet_in.acc = {{ 179.0, 180.0, 181.0 }};

    mavlink::rams_msg::msg::ACC_DATA packet1{};
    mavlink::rams_msg::msg::ACC_DATA packet2{};

    packet1 = packet_in;

    //std::cout << packet1.to_yaml() << std::endl;

    packet1.serialize(map1);

    mavlink::mavlink_finalize_message(&msg, 1, 1, packet1.MIN_LENGTH, packet1.LENGTH, packet1.CRC_EXTRA);

    packet2.deserialize(map2);

    EXPECT_EQ(packet1.time, packet2.time);
    EXPECT_EQ(packet1.acc, packet2.acc);
}

#ifdef TEST_INTEROP
TEST(rams_msg_interop, ACC_DATA)
{
    mavlink_message_t msg;

    // to get nice print
    memset(&msg, 0, sizeof(msg));

    mavlink_acc_data_t packet_c {
         123.0, { 179.0, 180.0, 181.0 }
    };

    mavlink::rams_msg::msg::ACC_DATA packet_in{};
    packet_in.time = 123.0;
    packet_in.acc = {{ 179.0, 180.0, 181.0 }};

    mavlink::rams_msg::msg::ACC_DATA packet2{};

    mavlink_msg_acc_data_encode(1, 1, &msg, &packet_c);

    // simulate message-handling callback
    [&packet2](const mavlink_message_t *cmsg) {
        MsgMap map2(cmsg);

        packet2.deserialize(map2);
    } (&msg);

    EXPECT_EQ(packet_in.time, packet2.time);
    EXPECT_EQ(packet_in.acc, packet2.acc);

#ifdef PRINT_MSG
    PRINT_MSG(msg);
#endif
}
#endif

TEST(rams_msg, ACC_CALIB)
{
    mavlink::mavlink_message_t msg;
    mavlink::MsgMap map1(msg);
    mavlink::MsgMap map2(msg);

    mavlink::rams_msg::msg::ACC_CALIB packet_in{};
    packet_in.time = 123.0;
    packet_in.mis_mat = {{ 179.0, 180.0, 181.0, 182.0, 183.0, 184.0, 185.0, 186.0, 187.0 }};
    packet_in.scale_mat = {{ 683.0, 684.0, 685.0, 686.0, 687.0, 688.0, 689.0, 690.0, 691.0 }};
    packet_in.bias_vec = {{ 1187.0, 1188.0, 1189.0 }};

    mavlink::rams_msg::msg::ACC_CALIB packet1{};
    mavlink::rams_msg::msg::ACC_CALIB packet2{};

    packet1 = packet_in;

    //std::cout << packet1.to_yaml() << std::endl;

    packet1.serialize(map1);

    mavlink::mavlink_finalize_message(&msg, 1, 1, packet1.MIN_LENGTH, packet1.LENGTH, packet1.CRC_EXTRA);

    packet2.deserialize(map2);

    EXPECT_EQ(packet1.time, packet2.time);
    EXPECT_EQ(packet1.mis_mat, packet2.mis_mat);
    EXPECT_EQ(packet1.scale_mat, packet2.scale_mat);
    EXPECT_EQ(packet1.bias_vec, packet2.bias_vec);
}

#ifdef TEST_INTEROP
TEST(rams_msg_interop, ACC_CALIB)
{
    mavlink_message_t msg;

    // to get nice print
    memset(&msg, 0, sizeof(msg));

    mavlink_acc_calib_t packet_c {
         123.0, { 179.0, 180.0, 181.0, 182.0, 183.0, 184.0, 185.0, 186.0, 187.0 }, { 683.0, 684.0, 685.0, 686.0, 687.0, 688.0, 689.0, 690.0, 691.0 }, { 1187.0, 1188.0, 1189.0 }
    };

    mavlink::rams_msg::msg::ACC_CALIB packet_in{};
    packet_in.time = 123.0;
    packet_in.mis_mat = {{ 179.0, 180.0, 181.0, 182.0, 183.0, 184.0, 185.0, 186.0, 187.0 }};
    packet_in.scale_mat = {{ 683.0, 684.0, 685.0, 686.0, 687.0, 688.0, 689.0, 690.0, 691.0 }};
    packet_in.bias_vec = {{ 1187.0, 1188.0, 1189.0 }};

    mavlink::rams_msg::msg::ACC_CALIB packet2{};

    mavlink_msg_acc_calib_encode(1, 1, &msg, &packet_c);

    // simulate message-handling callback
    [&packet2](const mavlink_message_t *cmsg) {
        MsgMap map2(cmsg);

        packet2.deserialize(map2);
    } (&msg);

    EXPECT_EQ(packet_in.time, packet2.time);
    EXPECT_EQ(packet_in.mis_mat, packet2.mis_mat);
    EXPECT_EQ(packet_in.scale_mat, packet2.scale_mat);
    EXPECT_EQ(packet_in.bias_vec, packet2.bias_vec);

#ifdef PRINT_MSG
    PRINT_MSG(msg);
#endif
}
#endif

TEST(rams_msg, ACC_CMD)
{
    mavlink::mavlink_message_t msg;
    mavlink::MsgMap map1(msg);
    mavlink::MsgMap map2(msg);

    mavlink::rams_msg::msg::ACC_CMD packet_in{};
    packet_in.cmd = 5;

    mavlink::rams_msg::msg::ACC_CMD packet1{};
    mavlink::rams_msg::msg::ACC_CMD packet2{};

    packet1 = packet_in;

    //std::cout << packet1.to_yaml() << std::endl;

    packet1.serialize(map1);

    mavlink::mavlink_finalize_message(&msg, 1, 1, packet1.MIN_LENGTH, packet1.LENGTH, packet1.CRC_EXTRA);

    packet2.deserialize(map2);

    EXPECT_EQ(packet1.cmd, packet2.cmd);
}

#ifdef TEST_INTEROP
TEST(rams_msg_interop, ACC_CMD)
{
    mavlink_message_t msg;

    // to get nice print
    memset(&msg, 0, sizeof(msg));

    mavlink_acc_cmd_t packet_c {
         5
    };

    mavlink::rams_msg::msg::ACC_CMD packet_in{};
    packet_in.cmd = 5;

    mavlink::rams_msg::msg::ACC_CMD packet2{};

    mavlink_msg_acc_cmd_encode(1, 1, &msg, &packet_c);

    // simulate message-handling callback
    [&packet2](const mavlink_message_t *cmsg) {
        MsgMap map2(cmsg);

        packet2.deserialize(map2);
    } (&msg);

    EXPECT_EQ(packet_in.cmd, packet2.cmd);

#ifdef PRINT_MSG
    PRINT_MSG(msg);
#endif
}
#endif
